<?php


namespace App\Http\Controllers\Api;

use Illuminate\Routing\Controller as BaseController;
use Illuminate\Http\Request;

class CommonController extends BaseController{

   public function returnJson($data, $status = 200, $op = []){
       $rec = ['data'=>$data, 'code'=>$status];

       if(is_array($op) && count($op) > 0) $rec = array_merge($rec, $op);

       return $rec;
   }

   public function returnJsonErr($err, $status = 10000, $op = []){
        $rec = ['code'=>$status, 'err'=>$err];

        if(is_array($op) && count($op) > 0) $rec = array_merge($rec, $op);

        return $rec;
    }

    public function hh($val){
        $rec = str_replace(array("\r\n", "\r", "\n"), "@hh@", $val);
        $rec = str_replace(array('"末"', '"位数"'),array('"未', '位数"'), $rec);
        return $rec;
    }

    /**
     * 处理json字符串换行符
     */
    public function jsonString($lists){
        $data = [];
        foreach($lists as $key=>$v){
            $v['options'] = $this->hh($v['options']);//str_replace(array("\r\n", "\r", "\n"), "@hh@", $v['options']); 
            $v['options'] = json_decode($v['options'], true);
            $data[$key] = $v;
        }

        return $data;
    }

}